package com.example.tsproject.mapper;

import com.example.tsproject.entity.Assignmentquestions;
import com.example.tsproject.entity.Assignments;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.tsproject.entity.AssignmentsWithStudentName;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
* @author 86183
* @description 针对表【assignments】的数据库操作Mapper
* @createDate 2025-03-11 12:25:59
* @Entity com.example.tsproject.entity.Assignments
*/
@Mapper
public interface AssignmentsMapper extends BaseMapper<Assignments>{
//    void insertAssignment(@Param("studentNumber") String studentNumber,
//                         @Param("stuNum") String stuNum,
//                         @Param("classNumber") String classNumber,
//                         @Param("name") String name,
//                         @Param("assignmentType") String assignmentType,
//                         @Param("startTime") Date startTime,
//                         @Param("endTime") Date endTime);
    void insertAssignment(Assignments assignment); // 参数改为实体类
    @Select("select * from assignments where publisher_number=#{publisher_Number} and assignment_type='type3';")
    List<Assignments> getExerciseList(@Param("publisher_Number") String publisher_Number);

    @Select("select * from assignments where stuNum=#{stuNumber} and assignment_type='type1';")
    List<Assignments> getHomeworkList(@Param("stuNumber") String stuNumber);

    @Select("select * from assignments where stuNum=#{stuNumber} and assignment_type=#{type};")
    List<Assignments> getAllTypeList(@Param("stuNumber") String stuNumber,@Param("type") String type);

    @Select("SELECT DISTINCT name, class_number, start_time, end_time ,isUse\n" +
            "FROM Assignments \n" +
            "WHERE publisher_number = #{tNumber} and assignment_type='type1';")
    List<Assignments> getAssignmentsList(@Param("tNumber") String tNumber);

    @Select("SELECT DISTINCT name, class_number, start_time, end_time ,isUse\n" +
            "FROM Assignments \n" +
            "WHERE publisher_number = #{tNumber} and assignment_type=#{type};")
    List<Assignments> getTExamsOrAssignmentsList(@Param("tNumber") String tNumber,@Param("type") String type);

    @Select("select * from Assignments where publisher_number=#{tNumber} and class_number=#{classNumber} and name=#{name};")
    List<Assignments> getStuWorkListByClass(@Param("tNumber") String tNumber, @Param("classNumber") String classNumber, @Param("name") String name);

    @Select("SELECT a.*, s.name AS studentName " +
            "FROM Assignments a " +
            "JOIN Students s ON a.stuNum = s.student_number " +
            "WHERE a.publisher_number=#{tNumber} AND a.class_number=#{classNumber} AND a.name=#{name};")
    List<AssignmentsWithStudentName> getStuWorkListWithStudentNameByClass(
        @Param("tNumber") String tNumber,
        @Param("classNumber") String classNumber,
        @Param("name") String name
    );

    void updateAssignmentScoreAndStatus(@Param("assignmentId") Integer assignmentId,
                                        @Param("score") BigDecimal score,
                                        @Param("isSubmit") String isSubmit);
    @Update("update assignments set isUse ='n' where id=#{assId} ")
    void delete(@Param("assId") Integer assId);

    @Update("update assignments set isUse ='n' where class_number=#{classNumber} and name=#{name} ")
    void Tdelete(@Param("classNumber") String classNumber, @Param("name") String name);

    @Select("SELECT EXISTS(SELECT 1 FROM assignments WHERE name = #{name})")
    Boolean findNameExist(String name);
}




